<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最小时间差</title>
</head>
<body>
  <script>
    var findminDifference = function(timePoints) {
      if(!Array.isArray(timePoints)) return
      const timeArray = timePoints.map((item)=>{
        return item = parseInt(item.substr(0, 2)) * 60 + parseInt(item.substr(3, 2))
      }).sort((a,b)=>{return a-b})
      let numList = []
      timeArray.forEach((item, i)=>{
        if(i > 0) {
          numList.push(Math.min(Math.abs(timeArray[i] - timeArray[i - 1]),1440 - Math.abs(timeArray[i] - timeArray[i - 1])))
        }
      })
      const lastchild = Math.abs(timeArray[timeArray.length - 1] - timeArray[0])
      numList.push(Math.min(lastchild,1440 - lastchild))
      numList.sort((a,b)=>{return a-b})
      return numList[0]
    }
    let data = ['00:00', '23:59', '00:00']
    // let data = ['23:59', '00:00']
    console.log(findminDifference(data));
  </script>
</body>
</html>